/**
 * 证书新增验证
 */
function checkCertificate() {
    var ids = getTableSelect("#myTable");
    if (checkTableSelect(ids,0)) {
        addCertificateCheck(ids[0]);
    }
}


/**
 * 新增证书验证
 */
function addCertificateCheck(productId) {
    DGG.loading()
    $.post(sysInfo.basePath + '/zs/general_credential/add_certificate_check.do', {productId: productId}, function (result) {
        if (result.code == 0) {
            addCertificate(productId);
        } else {
            DGG.Errors(result.msg);
        }
    }, 'json');
}

/**
 * 状态栏新增入库
 */
function addCertificateCheck1(productId) {
    DGG.loading()
    $.post(sysInfo.basePath + '/zs/general_credential/add_certificate_check1.do', {productId: productId}, function (result) {
        if (result.code == 0) {
            addCertificate(productId);
        } else {
            DGG.Errors(result.msg);
        }
    }, 'json');
}

/**
 * 新增证书
 */
function addCertificate(productId,talentRenewalType) {
    $.post(sysInfo.basePath + "/zs/general_credential/add_credential_page.html", {productId: productId}, function (data) {
        dgg.Open({
            type: 1,
            title: '新增证书',
            btn: ["确定", "取消"],
            content: data,
            area: '90%',
            yes: function () {
                DGG.loading();
                // 验证页面字段
                if (!checkCertificateFileds()) {
                    DGG.loading('close');
                    return false;
                }
                // 新增证书
                var params = $("#credentialForm").serializeObject();
                params.certificateSpecialtys = getTextVal('#certificateSpecialtys');
                params.certificateSpecialty = getVal('#certificateSpecialtys', 0);
                params.certificateTypeId = $("#certificateType option:selected").val();
                params.certificateType = $("#certificateType option:selected").html();
                params.baseId = $("#id").val();
                if (talentRenewalType !== ''){
                    params.talentRenewalType = talentRenewalType
                }
                countGuidePrice(params);

            }, end: function () {
                layer.closeAll("tips");
            }
        });
    });
}

/**
 * 证书需要验证的字段
 */
function checkCertificateFileds() {
    if (!$('select[name=isTalentAppearanceCoordinate]').val()){
        DGG.Tip("请选择人才出场是否配合",$('select[name=isTalentAppearanceCoordinate]'),{tips: [3, '#000'], time: 3000});
        return false;
    }
    if ($('select[name=socialSecurity]').val() === '0' ) {
        if (!$("input[name=socialSecurityAreaChange]").val()){
            DGG.Tip("请选择社保区域",$('input[name=socialSecurityAreaChange]'),{tips: [3, '#000'], time: 3000});
            return false;
        }
    }
    if (!$('select[name=socialSecurity]').val()){
        DGG.Tip("请选择是否购买社保",$('select[name=socialSecurity]'),{tips: [3, '#000'], time: 3000});
        return false;
    }
    if (!$('select[name=isTalentOriginalCopyCoordinate]').val()){
        DGG.Tip("请选择人才原件是否配合",$('select[name=isTalentOriginalCopyCoordinate]'),{tips: [3, '#000'], time: 3000});
        return false;
    }

    // 验证下拉选择框
    if (!$('select[name=talentPaymentMethod]').val() ) {
        DGG.Tip("请选择人才付款方式",$('select[name=talentPaymentMethod]'),{tips: [3, '#000'], time: 3000});
        return false;
    }
    if (!$('select[name=receiptType]').val() ) {
        DGG.Tip("请选择收证类型",$('select[name=receiptType]'),{tips: [3, '#000'], time: 3000});
        return false;
    } else if ($('select[name=receiptType]').val() === '0'){
        if (!checkInputBox('#channelName')) return false;
        if (!checkInputBox('#channelPhone')) return false;
        if (!checkInputBox('#channelIdCard')) return false;
    }


    if (!checkDropDownChoice('#certificateType', $('#certificateType').next(), '')) return false;
    if (!checkDropDownChoice('#certificateSpecialtys', $('#certificateSpecialtys').next())) return false;
    if (!checkCertificateSpecialty('#certificateType', '#certificateSpecialtys')) return false;
    if (!checkDropDownChoice('#certificateLevel', $('#certificateLevel').next())) return false;
    if (!checkDropDownChoice('#applicationScopes')) return false;
    if (!checkDropDownChoice('#isWhetherSign')) return false;
    if (!checkDropDownChoice('#isQuelificationCertificate')) return false;
    if (!checkDropDownChoice('#isGraduationCertificate')) return false;
    // if (!checkDropDownChoice('#isInformationCard')) return false;
    if (!checkDropDownChoice('#isGroupFiling')) return false;
    if (!checkInputBox('#contractSigningTimes')) return false;

    // 验证输入框
    if (!checkInputBox('[name="areaName"]', '请选择地区')) return false;
    // debugger
    if (!isFloatGteZeroByLength('#receiptPrice', 2, true, 8)) return false;
    if (!checkInputBox('#personalName')) return false;
    if (!isMobile('#personalPhone', true)) return false;
    if (!checkInputBox('#certificateName')) return false;
    if (!checkInputBox('#accountName')) return false;
    if (!checkInputBox('#accountBank')) return false;
    if (!isIdCardNo("#personalIdCard")) return false;
    if (!isWx('#personalWeixin')) return false;
    if (!regCheck(/^[0-9]\d*$/, '#accountNo', '请输入正确的银行卡号', true)) return false;
    if (!$("#certificateNo").val()) {
        DGG.Warning("证书编号不能为空");
        return false;
    }
    if (!checkCertificateNo("#certificateNo", 'GENERAL_CREDENTIAL', $('[name="id"]').val(), 1)) return false;
    return true;
}


/**
 * 新增证书
 * @param params
 */
function addCretificate(params) {
    $.post(sysInfo.basePath + "/zs/general_credential/add_certificate.do", params, function (result) {
        if (result.code == 0) {
            DGG.Alert_succeed(result.data.msg, '证书新增提示', {
                yes: function () {
                    search('#myTable', 'reload');
                    layer.closeAll();
                    setTimeout(function () {
                        DGG.loading('close');
                        window.parent.updateTab("证书信息列表:" + result.data.certificateNo, sysInfo.basePath + "/zs/general_credential/general_certificate_info.html?keywords=" + result.data.certificateNo);
                    }, 500);
                }, cancel: function () {
                    search('#myTable', 'reload');
                    layer.closeAll();
                    DGG.loading('close');
                }
            });
        } else {
            DGG.Errors(result.msg);
            DGG.loading('close');
        }

    });
}

/**
 * 显示社保区域
 */
function showSocialSecurityArea() {
    let socialSecurity = $('select[name=socialSecurity]').val();
    if (socialSecurity === '0'){
        $("#divSocialSecurityArea").css("display","block")
        $("span[name=isSocialSecurity]").css("display","inline-block")
    } else {
        $("#divSocialSecurityArea").css("display","none")
        $("span[name=isSocialSecurity]").css("display","none")
        $("input[name=socialSecurityAreaId]").val("")
        $("input[name=socialSecurityArea]").val("")
        $("input[name=socialSecurityAreaChange]").val("")
    }
}

/**
 * 显示渠道信息
 */
function receiptType1() {

    let receiptType = $('select[name=receiptType]').val();
    if (receiptType == 0 && receiptType != ''){
        $("span[name=receiptType]").css("display","inline-block")
        document.getElementById("channelName").readOnly=false;
        document.getElementById("channelPhone").readOnly=false;
        document.getElementById("channelIdCard").readOnly=false;
    } else {
        $("#channelName").val("");
        $("#channelPhone").val("");
        $("#channelIdCard").val("");
        $("span[name=receiptType]").css("display","none")
        document.getElementById("channelName").readOnly=true;
        document.getElementById("channelPhone").readOnly=true;
        document.getElementById("channelIdCard").readOnly=true;
    }
}